package com.example.workflow.controller;

import com.example.workflow.dto.ProcessStartDTO;
import com.example.workflow.dto.TaskCompleteDTO;
import com.example.workflow.service.ProcessOpenApiService;
import com.example.workflow.vo.ProcessDefinitionVO;
import com.example.workflow.vo.ProcessInstanceVO;
import com.example.workflow.vo.TaskVO;

import io.swagger.v3.oas.annotations.Operation;

import com.example.workflow.vo.ProcessInstanceDetailVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.example.workflow.common.Result;
@RestController
@RequestMapping("/api/open/process")
@RequiredArgsConstructor
public class ProcessOpenApiController {
    private final ProcessOpenApiService processOpenApiService;

    @Operation(summary = "获取流程定义列表")
    @GetMapping("/list/{systemId}")
    public Result<List<ProcessDefinitionVO>> listProcesses(@PathVariable Long systemId) {
        return Result.success(processOpenApiService.listProcesses(systemId));
    }

    @Operation(summary = "启动流程")
    @PostMapping("/start")
    public Result<String> startProcess(@RequestBody ProcessStartDTO startDTO) {
        String processInstanceId = processOpenApiService.startProcess(startDTO);
        return Result.success(processInstanceId);
    }

    @Operation(summary = "获取流程实例列表")
    @GetMapping("/instances/{systemId}")
    public Result<List<ProcessInstanceVO>> listInstances(@PathVariable Long systemId) {
        return Result.success(processOpenApiService.listProcessInstances(systemId));
    }

    @Operation(summary = "完成任务")
    @PostMapping("/complete-task")
    public Result<Void> completeTask(@RequestBody TaskCompleteDTO taskDTO) {
        processOpenApiService.completeTask(taskDTO);
        return Result.success();
    }

    @Operation(summary = "获取角色任务列表")
    @GetMapping("/tasks/{roleId}")
    public Result<List<TaskVO>> listRoleTasks(@PathVariable String roleId) {
        return Result.success(processOpenApiService.listRoleTasks(roleId));
    }

    @Operation(summary = "获取流程实例详情")
    @GetMapping("/instance/{processInstanceId}")
    public Result<ProcessInstanceDetailVO> getInstanceDetail(@PathVariable String processInstanceId) {
        return Result.success(processOpenApiService.getProcessInstanceDetail(processInstanceId));
    }
} 